package com.example.itensyuan0609;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;

import com.example.itensyuan0609.bin.MyBean;
import com.example.itensyuan0609.util.HttpUtil;

import java.io.IOException;

public class MyService extends Service {
    public static final String ACTION = "com.example.itensyuan0609.MyService";
    public MyService() {
    }

    private void getDataFromServer() {
        final HttpUtil util = new HttpUtil();
        new Thread() {
            @Override
            public void run() {
                try {
                    MyBean myBean = util.connetServer();
                    Intent intent = new Intent();
                    intent.setAction(ACTION);
                    intent.putExtra("myBean", myBean);
                    sendBroadcast(intent);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }.start();
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        getDataFromServer();
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public IBinder onBind(Intent intent) {
        // TODO: Return the communication channel to the service.
        throw new UnsupportedOperationException("Not yet implemented");
    }
}
